package com.qk.controller;

import com.qk.Response.Result;
import com.qk.dto.LoginDTO;
import com.qk.vo.user.UserLoginVO;
import com.qk.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private UserService userService;

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result login(@RequestBody LoginDTO  loginDTO) {
        log.info("用户登录请求: {}", loginDTO);
        //从数据库中查询用户名和用户密码，如果存在则返回用户的账号密码信息，不存在则返回错误信息
        UserLoginVO loginResult = userService.login(loginDTO.getUsername(), loginDTO.getPassword());
        return Result.success(loginResult);
    }

}